﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTOFrameworks;
using System.IO;
/*
namespace FAQFrameworks
{
    public class ForumDirectoryVisitor : ITreeVisitor<Forum>, ICloneable
    {
        public string[] fileList;
        int index;

        public bool SetCurrentPath(string currentPath)
        {
            string parentPath = GetParentPath(currentPath);

            bool exists = Directory.Exists(parentPath);

            if (exists)
            {
                string[] paths = Directory.GetDirectories(parentPath);

                if (paths.Length > 0)
                {
                    fileList = paths;

                    for (int i = 0; i < fileList.Length; i++)
                    {
                        if (fileList[i] == currentPath)
                        {
                            index = i;

                            return true;
                        }
                    }
                }
            }

            return false;
        }

        public ForumDirectoryVisitor(string path)
        {
            SetCurrentPath(path);
        }

        string GetParentPath(string path)
        {
            path.TrimEnd
                (new char[] { Path.DirectorySeparatorChar });
            int index
                = path.LastIndexOf(Path.DirectorySeparatorChar);

            string newPath = path.Substring(0, index);

            return newPath;
        }

        void ClearFileList()
        {
            fileList = null;
        }

        bool TryCurrentPath()
        {
            if (index < fileList.Length)
            {
                if (Directory.Exists(fileList[index]))
                {
                    return true;
                }
            }

            return false;
        }

        #region ITreeVisitor<Forum> 成员

        public bool MoveTo(Forum f)
        {
            throw new NotImplementedException();
        }

        public bool MoveUp()
        {
            string currentPath = fileList[index];

            string parentPath = GetParentPath(currentPath);

            return SetCurrentPath(parentPath);
        }

        public bool MoveNext()
        {
            index++;

            bool result = TryCurrentPath();

            if (!result)
            {
                index--;
                return false;
            }

            return true;
        }

        public bool MoveFirstChild()
        {
            if (TryCurrentPath())
            {
                string currentPath = fileList[index];

                string[] paths = Directory.GetDirectories(currentPath);

                if (paths.Length > 0)
                {
                    fileList = paths;
                    index = 0;

                    return true;
                }
            }

            return false;
        }

        public Forum GetValue()
        {
            string currentPath = fileList[index];

            bool exists = Directory.Exists(currentPath);
            if (exists)
            {
                Forum forum = new Forum();
                forum.ForumName = Path.GetFileName(currentPath);

                // 使用路径的Hash码作为唯一编码
                forum.ForumId = currentPath.GetHashCode();

                forum.Path = currentPath;

                return forum;
            }

            return null;
        }

        #endregion

        #region ICloneable 成员

        public object Clone()
        {
            string currentPath = fileList[index];

            ForumDirectoryVisitor visitor = new ForumDirectoryVisitor(currentPath);

            return visitor;
        }

        #endregion
    }
}
*/